package com.idol.logger.utils

internal fun <E> Collection<E>.asNull() = if (this.isEmpty()) null else this

internal fun <K, V> Map<K, V>.asNull() = if (this.isEmpty()) null else this

internal fun <T> asNull(source: T, boolean: Boolean) = if (boolean) null else source

internal fun <T> asNull(source: T, transform: (T) -> Boolean) = asNull(source, transform.invoke(source))

// 重载操作符*，"a" * 3 = "aaa"
internal operator fun String.times(time: Int) = let {
    if (time < 1) throw IllegalArgumentException("time >= 1")
    (0 until time).joinToString("") { _ -> it }
}

internal fun findClassByClassName(className: String): Boolean = try {
    Class.forName(className)
    true
} catch (e: ClassNotFoundException) {
    false
}